{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 2,
   "id": "a7136145",
   "metadata": {},
   "outputs": [],
   "source": [
    "#方案1：定义一系列数值常量或枚举类型\n",
    "#方案2：使用标准库中collection.namedtuple替换内置tuple"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "id": "1afb86dc",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "('chenmengyuan', 23, 'male', 'xxxxxx@qq.com')"
      ]
     },
     "execution_count": 5,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "#学生信息\n",
    "s = ('chenmengyuan',23,'male','xxxxxx@qq.com')\n",
    "s"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "id": "60241aac",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "('1', 'teacher1', 41, 'xxxxxx@qq.com')"
      ]
     },
     "execution_count": 6,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "#教师信息\n",
    "t=('1','teacher1',41,'xxxxxx@qq.com')\n",
    "t"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "id": "ea966e08",
   "metadata": {},
   "outputs": [],
   "source": [
    "#方案1.1 使用数值常量\n",
    "s_name,s_age,s_sex,s_mail = range(4)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 14,
   "id": "34c2a868",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "'chenmengyuan'"
      ]
     },
     "execution_count": 14,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "#查询\n",
    "s[s_name]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 20,
   "id": "f9bbc6c0",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "'chenmengyuan'"
      ]
     },
     "execution_count": 20,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# 方案1.2 使用枚举类型\n",
    "from enum import IntEnum\n",
    "class StudentEnum(IntEnum):\n",
    "    NAME = 0\n",
    "    AGE = 1\n",
    "    SEX = 2\n",
    "    EMAIL = 3\n",
    "s[StudentEnum.NAME]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 28,
   "id": "ac828470",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "Student(name='chenmengyuan', age=23, sex='male', email='xxxxxx@qq.com')"
      ]
     },
     "execution_count": 28,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "#方案2 使用标准库中collections.namedtuple替换内置tuple\n",
    "from collections import namedtuple\n",
    "Student = namedtuple('Student',['name','age','sex','email'])\n",
    "student_mengyuan = Student('chenmengyuan', 23, 'male', 'xxxxxx@qq.com')\n",
    "student_mengyuan"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 30,
   "id": "a6bfbd52",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "'chenmengyuan'"
      ]
     },
     "execution_count": 30,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "student_mengyuan.name"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "15234f3e",
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.7.9"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
